﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ImgController : ControllerBase
    {
        public ImgController(IWebHostEnvironment web)
        {
            Web = web;
        }

        public IWebHostEnvironment Web { get; }
        [HttpPost]
        public IActionResult Img(IFormFile file)
        {
            string newfilename=Guid.NewGuid().ToString();
            string path=Web.WebRootPath+@"/Pic/"+newfilename+file.FileName;
            using (FileStream fs = System.IO.File.Create(path))
            {
                file.CopyTo(fs);
                fs.Close();
            }
            return Ok("/Pic/" + newfilename + file.FileName);
        }
    }
}
